<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="科目名称" prop="commodityType">
        <el-cascader ref="subjectId" v-model="subjectId" :options="subjectOptions" :props="props" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="账户名称" prop="accountName">
        <el-select v-model="queryParams.accountName" clearable placeholder="请选择" @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.cld_account_name" :key="dict.value" :label="dict.label"
                     :value="parseInt(dict.value)"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入公司名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCardNo">
        <el-input v-model="queryParams.bankCardNo" placeholder="请输入银行卡号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="收支类型" prop="operaType">
        <el-select v-model="queryParams.operaType" placeholder="请选择收支类型" clearable>
          <el-option v-for="item in operaType" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="accountDetailsList" border>
      <el-table-column label="账户名称" align="center" prop="accountName" width="200px;"/>
      <el-table-column label="科目编号" align="center" prop="subjectNo" width="200px;"/>
      <el-table-column label="科目名称" align="center" prop="subjectName" width="200px;"/>
      <el-table-column label="项目名称" align="center" prop="projectName" width="200px;"/>
      <el-table-column label="收支类型" align="center" prop="operaType" width="100px;">
        <template slot-scope="scope">
          <span>{{ scope.row.operaType === 1 ? '收入' : '支出' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划支付时间" align="center" prop="planTime" width="150px;">
        <template slot-scope="scope">
          <span>{{ scope.row.planTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收支时间" align="center" prop="paymentTime" width="150px;">
        <template slot-scope="scope">
          <span>{{ scope.row.paymentTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="应付金额" align="center" prop="answerAmount" width="150px;">
        <template slot-scope="scope">
          {{ toMoney(scope.row.answerAmount) }}
        </template>
      </el-table-column>
      <el-table-column label="实际金额" align="center" prop="realAmount" width="150px;">
        <template slot-scope="scope">
          {{ toMoney(scope.row.realAmount) }}
        </template>
      </el-table-column>
      <el-table-column label="支付人" align="center" prop="paymentName" width="120px;"/>
      <el-table-column label="摘要" align="center" prop="remark" />
      <el-table-column label="创建人名称" align="center" prop="createName" width="120px;"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160px;">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>

  </div>
</template>
<script>
import { listAccountDetails } from "@/api/cld/accountDetails";
import { getList } from '@/api/cld/project'
import { listSubject, } from "@/api/cld/subject";

export default {
  name: "flowing",
  dicts: ['cld_account_name',],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 账户流水明细表格数据
      accountDetailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 30,
        accountName: null,
        companyName: null,
        projectName: null,
        backCardNo: null,
        subjectId: null,
        operaType: null,
      },
      // 表单参数
      form: {},
      // 收支类型
      operaType: [{
        value: '1',
        label: '收入'
      }, {
        value: '2',
        label: '支出'
      }],
      // 项目列表
      projectOptions: [],
      // 科目配置选项
      subjectId: [],
      subjectOptions: [],
      props: {
        multiple: true,
        checkStrictly: true,
        value: "subjectId",
        label: "subjectName",
      },
    };
  },
  created() {
      this.getList();
      this.getListSubject();
      this.handleGetProjectList();
  },
  methods: {
    /** 查询银行流水明细列表 */
    getList() {
      this.loading = false;
      listAccountDetails(this.queryParams).then(response => {
        this.accountDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 获取科目列表 */
    getListSubject() {
      listSubject().then((response) => {
        this.subjectOptions = this.handleTree(
          response.data,
          "subjectId",
          "subjectPid"
        );
      });
    },
    // 查询项目列表
    handleGetProjectList() {
      getList({
        projectStatus: 2
      }).then(res => {
        this.projectOptions = res.data;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        accountName: null,
        bankCardNo: null,
        companyName: null,
        openName: null,
        subjectId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      let nodes = this.$refs.subjectId.getCheckedNodes();
      if (nodes.length > 0 && this.subjectId.length > 0) {
        let nodeIds = nodes.map((item) => item.value);
        this.queryParams.subjectId = nodeIds.join(",");
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>
<style scoped>
.app-container{
  padding:0px;
}
</style>
